package com.smh.a01MapDemo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo3 {
    public static void main(String[] args) {

        Map<Integer,String> map = new HashMap<>();
        map.put(1,"asd");
        map.put(2,"qwe");
        map.put(3,"zxc");
        map.put(4,"fgh");
        System.out.println(map);

        //键值对对象,返回set集合
        //集合的元素是键值对对象
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        System.out.println(entries);
        for (Map.Entry<Integer, String> entry : entries) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+","+value);
        }
        System.out.println("----------------");

        entries.forEach(entry->{
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+","+value);
        });
        System.out.println("----------------");

        Iterator<Map.Entry<Integer, String>> it = entries.iterator();
        while (it.hasNext()){
            Map.Entry<Integer, String> entry = it.next();
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+","+value);
        }
        System.out.println("---------------");

        for (Map.Entry<Integer, String> e : map.entrySet()) {
            Integer key = e.getKey();
            String value = e.getValue();
            System.out.println(key+","+value);
        }


    }
}
